package com.bor.gb.rest.util;

import com.bor.gb.db.domain.Guide;
import com.bor.gb.db.domain.PlaceNote;
import com.bor.gb.rest.model.GuideResponse;
import com.bor.gb.rest.model.PlaceNoteResponse;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by bor on 12/24/14.
 */
@Component
public class EntityConverter {

    public List<GuideResponse> guidesToGuideResponses(List<Guide> guides) {
        return guides.stream().map(guide -> guideToGuideResponse(guide)).collect(Collectors.toList());
    }


    public GuideResponse guideToGuideResponse(Guide guide) {
        GuideResponse response = new GuideResponse();
        response.setName(guide.getName());
        response.setDescription(guide.getDescription());
        response.setId(guide.getId());
        List<PlaceNoteResponse> notes = new ArrayList<>();
        for (PlaceNote note : guide.getEntries()) {
            notes.add(new PlaceNoteResponse(note.getTitle(), note.getContent()));

        }

        response.setEntries(notes);
        return response;
    }
}
